﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;

namespace Pear.Database.Migrations.Migrations
{
    public partial class v008 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SystemDataCategory",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(32) CHARACTER SET utf8mb4", maxLength: 32, nullable: false),
                    Remark = table.Column<string>(type: "varchar(200) CHARACTER SET utf8mb4", maxLength: 200, nullable: true),
                    Sequence = table.Column<int>(type: "int", nullable: false),
                    HigherId = table.Column<int>(type: "int", nullable: true),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SystemDataCategory", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SystemDataCategory_SystemDataCategory_HigherId",
                        column: x => x.HigherId,
                        principalTable: "SystemDataCategory",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "SystemData",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(32) CHARACTER SET utf8mb4", maxLength: 32, nullable: false),
                    Remark = table.Column<string>(type: "varchar(200) CHARACTER SET utf8mb4", maxLength: 200, nullable: true),
                    Sequence = table.Column<int>(type: "int", nullable: false),
                    CategoryId = table.Column<int>(type: "int", nullable: false),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SystemData", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SystemData_SystemDataCategory_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "SystemDataCategory",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "SystemDataCategory",
                columns: new[] { "Id", "CreatedTime", "HigherId", "IsDeleted", "Name", "Remark", "Sequence", "UpdatedTime" },
                values: new object[] { 1, new DateTimeOffset(new DateTime(2020, 12, 22, 15, 30, 20, 0, DateTimeKind.Unspecified), new TimeSpan(0, 8, 0, 0, 0)), null, false, "性别", "性别", 0, null });

            migrationBuilder.InsertData(
                table: "SystemData",
                columns: new[] { "Id", "CategoryId", "CreatedTime", "IsDeleted", "Name", "Remark", "Sequence", "UpdatedTime" },
                values: new object[] { 1, 1, new DateTimeOffset(new DateTime(2020, 12, 22, 15, 30, 20, 0, DateTimeKind.Unspecified), new TimeSpan(0, 8, 0, 0, 0)), false, "男", "男", 0, null });

            migrationBuilder.InsertData(
                table: "SystemData",
                columns: new[] { "Id", "CategoryId", "CreatedTime", "IsDeleted", "Name", "Remark", "Sequence", "UpdatedTime" },
                values: new object[] { 2, 1, new DateTimeOffset(new DateTime(2020, 12, 22, 15, 30, 20, 0, DateTimeKind.Unspecified), new TimeSpan(0, 8, 0, 0, 0)), false, "女", "女", 1, null });

            migrationBuilder.CreateIndex(
                name: "IX_SystemData_CategoryId",
                table: "SystemData",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_SystemDataCategory_HigherId",
                table: "SystemDataCategory",
                column: "HigherId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SystemData");

            migrationBuilder.DropTable(
                name: "SystemDataCategory");
        }
    }
}